//
//  CustomView.m
//  TestCoreMotion
//
//  Created by qm on 15/3/23.
//  Copyright (c) 2015年 qm. All rights reserved.
//

#import "CustomView.h"

@implementation CustomView

-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect{
    // Drawing code
//    //1.获取图形上下文
//    CGContextRef ctx=UIGraphicsGetCurrentContext();
//    
//    //2.绘图（画线）
//    //设置起点
//    CGContextMoveToPoint(ctx, 20, 20);
//    //设置终点
//    CGContextAddLineToPoint(ctx, 200, 300);
//    //渲染
//    CGContextStrokePath(ctx);
    
    
    //1.获取图形上下文
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    
    //2.绘图
    //2.a 画一条直线
    //2.a.1创建一条绘图的路径
    //注意：但凡通过Quartz2D中带有creat/copy/retain方法创建出来的值都必须要释放
    CGMutablePathRef path=CGPathCreateMutable();
    
    //2.a.2把绘图信息添加到路径里
    CGPathMoveToPoint(path, NULL, 20, 20);
    CGPathAddLineToPoint(path, NULL, 200, 300);
    
    //2.a.3把路径添加到上下文中
    //把绘制直线的绘图信息保存到图形上下文中
    CGContextAddPath(ctx, path);


    CGContextStrokePath(ctx);
    
    //第一种方法
    CGPathRelease(path);
 //   CGPathRelease(path1);
    //第二种方法
    //    CFRelease(path);
}


@end
